package day0213;

import java.util.Arrays;

public class Insertion {

    public static void main(String[] args) {
        /*
            插入排序
         */
        int[] arr = {3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48};

        for (int i = 1; i < arr.length; i++) {
            int j = i - 1;
            int current = arr[i];
            while(j >= 0){
                // 比较
                if (current < arr[j]) {
                    arr[j + 1] = arr[j];
                    j --;
                } else {
                    break;
                }
            }
            arr[++ j] = current;
        }

        System.out.println(Arrays.toString(arr));
    }
}
